from microbit import *

def resetFan():
    for A in['J1','J2','J3','J4']:
        fans.set_fans(A,0)

class FANS(object):
    def __init__(self):
        self.__pins = {
            'J1': pin1,
            'J2': pin2,
            'J3': pin13,
            'J4': pin15
        }

    def set_fans(self, RJPin, state, speed=100.0):
        if state == 0:
            self.__pins[RJPin].write_analog(0)
        elif state == 1:
            speed = ((speed - 0) * (1023 - 0)) / (100 - 0) + 0
            self.__pins[RJPin].write_analog(int(speed))

fans = FANS()
resetFan()


